package com.shijie.sjoj.service.provider.configure;

import com.shijie.sjoj.model.base.BaseValueEnumSerialize;
import com.shijie.sjoj.model.component.LogAnsi;
import com.shijie.sjoj.model.typehandler.BaseValueEnumSerializeTypeHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Mybatis配置类
 */
@Slf4j
@Configuration
public class MybatisConfig {

    /**
     * 注册类型处理器
     *
     * @return ConfigurationCustomizer（配置定制器）
     */
    @Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer() {
        return configuration -> {
            TypeHandlerRegistry registry = configuration.getTypeHandlerRegistry();
            registry.register(BaseValueEnumSerialize.class, BaseValueEnumSerializeTypeHandler.class);
//            registry.register(BaseValueEnumSerializeTypeHandler.class);
            log.info(LogAnsi.green("--- 注册mapper类型处理：【{}】"), BaseValueEnumSerializeTypeHandler.class);
        };
    }
}
